using System;
using System.Collections.Generic;
using System.Text;
using THSERP.BusinessEntities;
using THSERP.BaseProvider;
namespace THSERP.Modules.Project
{
    public class ProjectModule : BaseModuleERP
    {
        #region Constants
        public const String cstProjectTypeManual = "Manual";
        public const String cstProjectTypeFromTemplate = "FromTemplate";

        public const String cstProjectPhaseResourceEmployee = "Employee";
        public const String cstProjectPhaseResourceEquipment = "Equipment";
        public const String cstProjectPhaseResourceMaterial = "Material";
        #endregion

        public ProjectModule()
        {
            Name = "Project";
            CurrentModuleEntity = new ProjectEntities();
            CurrentModuleEntity.Module = this;
            InitializeModule();
        }

        public override void ActionNew()
        {
            base.ActionNew();

            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            ((PMProjectsInfo)entity.MainObject).PMProjectType = ProjectModule.cstProjectTypeManual;
        }

        #region Functions for Project Phases
        public void AddItemToPMProjectPhaseList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseItemsEntityList.AddObjectToList();
        }

        public void ChangeItemFromPMProjectPhaseList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseItemsEntityList.ChangeObjectFromList();
        }

        public void DeleteItemFromPMProjectPhaseList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseItemsEntityList.RemoveSelectedRowObjectFromList();
        }
        #endregion

        #region Functions for Project Phase Resource Employees
        public void AddItemToPMProjectPhaseResourceEmployeesList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceEmployee;
            entity.PMProjectPhaseResourceEmployeesList.AddObjectToList();
        }

        public void ChangeItemFromPMProjectPhaseResourceEmployeesList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceEmployee;
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceQty = 1;
            entity.PMProjectPhaseResourceEmployeesList.ChangeObjectFromList();
        }

        public void DeleteItemFromPMProjectPhaseResourceEmployeesList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseResourceEmployeesList.RemoveSelectedRowObjectFromList();
        }
        #endregion

        #region Functions for Project Phase Resource Equipments
        public void AddItemToPMProjectPhaseResourceEquipmentsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceEquipment;
            entity.PMProjectPhaseResourceEquipmentsList.AddObjectToList();
        }

        public void ChangeItemFromPMProjectPhaseResourceEquipmentsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceEquipment;
            entity.PMProjectPhaseResourceEquipmentsList.ChangeObjectFromList();
        }

        public void DeleteItemFromPMProjectPhaseResourceEquipmentsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseResourceEquipmentsList.RemoveSelectedRowObjectFromList();
        }
        #endregion

        #region Functions for Project Phase Resource Materials
        public void AddItemToPMProjectPhaseResourceMaterialsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            ((PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName]).PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceMaterial;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceMaterial;
            entity.PMProjectPhaseResourceMaterialsList.AddObjectToList();
        }

        public void ChangeItemFromPMProjectPhaseResourceMaterialsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            ((PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName]).PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceMaterial;
            PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
            objProjectPhaseResourcesInfo.PMProjectPhaseResourceType = ProjectModule.cstProjectPhaseResourceMaterial;
            entity.PMProjectPhaseResourceMaterialsList.ChangeObjectFromList();
        }

        public void DeleteItemFromPMProjectPhaseResourceMaterialsList()
        {
            ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
            entity.PMProjectPhaseResourceMaterialsList.RemoveSelectedRowObjectFromList();
        }
        #endregion

        private void THSLookupEditEmployee_Validated(object sender, EventArgs e)
        {
            THSLookupEdit lke = (THSLookupEdit)sender;
            if (lke != null)
            {
                int iEmployeeID = Convert.ToInt32(lke.EditValue);
                if (iEmployeeID > 0)
                {
                    HREmployeesController objEmployeesController = new HREmployeesController();
                    HREmployeesInfo objEmployeesInfo = (HREmployeesInfo)objEmployeesController.GetObjectByID(iEmployeeID);
                    if (objEmployeesInfo != null)
                    {
                        ProjectEntities entity = (ProjectEntities)CurrentModuleEntity;
                        PMProjectPhaseResourcesInfo objProjectPhaseResourcesInfo = (PMProjectPhaseResourcesInfo)entity.ModuleObjects[ProjectEntities.strPMProjectPhaseResourcesObjectName];
                        objProjectPhaseResourcesInfo.PMProjectPhaseResourceUnitCost = objEmployeesInfo.HREmployeeUnitCost;
                        objProjectPhaseResourcesInfo.PMProjectPhaseResourceQty = 1;
                        entity.UpdateModuleObjectBindingSource(ProjectEntities.strPMProjectPhaseResourcesObjectName);
                    }
                }
            }
        }
    }
}
